import request from '@/utils/request'
//告警台账列表
export function getAlarmList(data) {
  return request({
    url: '/alarm/pageV2',
    method: 'post',
    data
  })
}

//告警筛选条件
export function getDefectAlarmOption(params) {
  return request({
    url: `/alarm/defectAlarmOption/${params}`,
    method: 'get'
  })
}

//我的处理告警
export function getMyHandleAlarmList(data) {
  return request({
    url: `/alarm/myHandleAlarmV2`,
    method: 'post',
    data
  })
}

//我的处理告警统计
export function alarmCountMyHandleAlarm(data) {
  return request({
    url: `/alarm/countMyHandleAlarm`,
    method: 'post',
    data
  })
}


//人工校验
export function setAlarmAlgAnalyze(serialCode, data) {
  return request({
    url: `/alarm/algAnalyze/${serialCode}`,
    method: 'post',
    data
  })
}

//处理记录
export function alarmRecord(serialCode) {
  return request({
    url: `/alarm/record/v2/${serialCode}`,
    method: 'get'
  })
}

//处理告警
export function setAlarmProcess(resource, data) {
  return request({
    url: `/alarm/process/${resource}`,
    method: 'post',
    data
  })
}



//导出我的告警
export function exportMyHandleAlarm(data) {
  return request({
    url: `/alarm/exportMyHandleAlarmV2`,
    method: 'post',
    data,
    responseType: 'blob',
    timeout: 1000 * 60 * 60,
  })
}

//导出告警台账
export function exportAlarmResult(data) {
  return request({
    url: `/alarm/exportAlarmResultV2`,
    method: 'post',
    data,
    responseType: 'blob',
    timeout: 1000 * 60 * 60,
  })
}


//归因分析导出
export function exportalgGraphData(serialCode) {
  return request({
    url: `/alarm/exportalgGraphData/${serialCode}`,
    method: 'get',
    responseType: 'blob'
  })
}

//不良趋势导出
export function exportDefectRatioTrend(serialCode) {
  return request({
    url: `/alarm/exportDefectRatioTrend/${serialCode}`,
    method: 'get',
    responseType: 'blob'
  })
}

//不良趋势图表
export function defectRatioTrend(params) {
  return request({
    url: `/alarm/defectRatioTrend`,
    method: 'get',
    params
  })
}


//MAP图表
export function mapFocusGraphData(serialCode, params) {
  return request({
    url: `/alarm/mapFocusGraphDataV2/${serialCode}`,
    method: 'get',
    params
  })
}
export function mapLayout(serialCode) {
  return request({
    url: `/alarm/layout/${serialCode}`,
    method: 'get'
  })
}
//QTime明细
export function qTimeDetail(serialCode, params) {
  return request({
    url: `/alarm/qTimeDetail/${serialCode}`,
    method: 'get',
    params
  })
}
//QTime导出
export function exportQTimeDetail(serialCode, key) {
  return request({
    url: `/alarm/exportQTimeDetail/${serialCode}?key=${key}`,
    method: 'get',
    responseType: 'blob'
  })
}
//上传附件
export function alarmUploadFile(code, data) {
  return request({
    url: `/file/upload/${code}`,
    method: 'post',
    data
  })
}

//下载附件
export function alarmDownloadFile(id) {
  return request({
    url: `/file/download/${id}`,
    method: 'post',
    responseType: 'blob'
  })
}

//告警触发类别
export function alarmTriggerMode() {
  return request({
    url: `/alarm/triggerMode`,
    method: 'get',
  })
}

//我处置的告警组织
export function alarmMyHandleAlarmOrg(params) {
  return request({
    url: `/alarm/myHandleAlarm/org`,
    method: 'get',
    params
  })
}

//告警统计
export function alarmCountAlarm(data) {
  return request({
    url: `/alarm/countAlarm`,
    method: 'post',
    data
  })
}

//告警等级
export function alarmAlarmLevel() {
  return request({
    url: `/alarm/alarmLevel`,
    method: 'get',
  })
}

//修改告警
export function alarmUpdate(data) {
  return request({
    url: `/alarm`,
    method: 'put',
    data
  })
}

//Test标记新增或修改
export function alarmTestRemak(data) {
  return request({
    url: `/alarm/testRemak`,
    method: 'post',
    data
  })
}

export function alarmCauseAnalysis(data) {
  return request({
    url: `/alarm/causeAnalysis`,
    method: 'post',
    data
  })
}

export function causeAnalysisFactory(params) {
  return request({
    url: `/causeAnalysis/factory`,
    method: 'get',
    params
  })
}

export function causeAnalysisFirstClass(params) {
  return request({
    url: `/causeAnalysis/firstClass`,
    method: 'get',
    params
  })
}

export function causeAnalysisSecondClass(params) {
  return request({
    url: `/causeAnalysis/secondClass`,
    method: 'get',
    params
  })
}

// AI改善监控
// 获取OperCode
export function getOperCode(params) {
  return request({
    url: `/dictionary/operCode`,
    method: 'post',
    data: params
  })
}

// 获取 EqpId
export function getEqpId(params) {
  return request({
    url: `/dictionary/eqpId`,
    method: 'post',
    data: params
  })
}

// 获取 UnitId
export function getUnitId(params) {
  return request({
    url: `/dictionary/unitId`,
    method: 'post',
    data: params
  })
}
// 上传文件
export function uploadFile(params, serialCode) {
  return request({
    url: `/file/upload/${serialCode}`,
    method: 'post',
    data: params
  })
}

// 添加改善监控
export function addImproveMonitor(params) {
  return request({
    url: `/aiImproveMonitor`,
    method: 'post',
    data: params
  })
}

// 查询ai改善监控列表
export function getImproveMonitor(params) {
  return request({
    url: `/aiImproveMonitor/get`,
    method: 'get',
    params
  })
}

// 查询ai改善监控-chart
export function getImproveMonitorChart(params) {
  return request({
    url: `/aiImproveMonitor/chart`,
    method: 'get',
    params: params
  })
}
// 查询ai改善监控-chart
export function getImproveMonitorChartOption(data) {
  return request({
    url: `/aiImproveMonitor/chart/${data.id}`,
    method: 'post',
    data
  })
}
// 查询ai改善监控-产品型号
export function getProductModelList(params) {
  return request({
    url: `/agility/analytics/modes`,
    method: 'get',
    params
  })
}

// 查询ai改善监控-产品id
export function getProductIdList(params) {
  return request({
    url: `/agility/analytics/productId`,
    method: 'get',
    params
  })
}

// 添加和更新矫正结论
export function addCorrectConclusion(params) {
  return request({
    url: `/aiImproveMonitor/cc`,
    method: 'post',
    data: params
  })
}

// 获取矫正结论
export function getCorrectConclusion(params) {
  return request({
    url: `/aiImproveMonitor/cc`,
    method: 'get',
    params
  })
}
export function dVGraphData(params) {
  return request({
    url: `/alarm/dVGraphData/v2`,
    method: 'get',
    params
  })
}

export function defectAlarmOptionPerson() {
  return request({
    url: `/alarm/defectAlarmOptionPerson`,
    method: 'get'
  })
}


export function defectAlarmOptionData(params) {
  return request({
    url: `/alarm/defectAlarmOptionData`,
    method: 'get',
    params
  })
}

export function getAlarmFile(params) {
  return request({
    url: `/alarm/getAlarmFile`,
    method: 'get',
    params
  })
}
export function downloadAlarmFile(serialCode) {
  return request({
    url: `/alarm/downloadAlarmFile/${serialCode}`,
    method: 'get',
    responseType: 'blob'
  })
}


export function defectDetail(params) {
  return request({
    url: `/alarm/defectDetail`,
    method: 'get',
    params
  })
}

export function alarmLatestStatus(params) {
  return request({
    url: `/alarm/alarmLatestStatus`,
    method: 'get',
    params
  })
}

export function setV2process(resource, data) {
  if (Array.isArray(data)) {
    let orgInfo = data.map(it => `${it.orgName}${it.processorName}`).join('、')
    data.forEach(it => {
      it.prevResource = it.prevResource + ':' + orgInfo
    })
  }
  return request({
    url: `/alarm/process/v2/${resource}`,
    method: 'post',
    data
  })
}
export function distribute2Closed(data) {
  return request({
    url: `/alarm/distribute2Closed`,
    method: 'post',
    data
  })
}
export function deleteAlarm(id) {
  return request({
    url: `/alarm/${id}`,
    method: 'delete',
  })
}
export function troubleshootingReply(data) {
  return request({
    url: `/alarm/troubleshootingReply`,
    method: 'put',
    data
  })
}

export function addRule(data) {
  return request({
    url: `/yieldRule/addRule`,
    method: 'post',
    data
  })
}

export function queryRules(data) {
  return request({
    url: `/yieldRule/queryRules`,
    method: 'post',
    data
  })
}
export function batchDelRule(ids) {
  return request({
    url: `/yieldRule/batchDelRule/${ids}`,
    method: 'delete',
  })
}
export function getAssociatedSerialCode(data) {
  return request({
    url: `/alarm/getAssociatedSerialCode`,
    method: 'post',
    data
  })
}
//召回
export function alarmWithdrawProcess(data) {
  return request({
    url: `/alarm/withdrawProcess`,
    method: 'post',
    data
  })
}
//获取指定流程的子流程
export function getSubTraceIdRecord(data) {
  return request({
    url: `/alarm/getSubTraceIdRecord`,
    method: 'post',
    data
  })
}

//告警详情
export function alarmDetail(serialCode) {
  return request({
    url: `/alarm/${serialCode}`,
    method: 'get'
  })
}

//异常归因分析详情
export function alarmAlgAnalyze(serialCode, params) {
  return request({
    url: `/alarm/algAnalyze/${serialCode}`,
    method: 'get',
    params
  })
}
//归因分析-算法列表
export function getAlarmAlgorithmType() {
  return request({
    url: `/alarm/algorithmType`,
    method: 'get'
  })
}

//归因分析图表
export function algGraphData(serialCode, params) {
  return request({
    url: `/alarm/algGraphDataV2/${serialCode}`,
    method: 'get',
    params
  })
}
//array端设备别和时间别
export function algArrayGraphDataV2(serialCode, type, params) {
  return request({
    url: `/alarm/algArrayGraphDataV2/${serialCode}/${type}`,
    method: 'get',
    params
  })
}

//CST别图表
export function getCSTChartData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/cst/data`,
    method: 'post',
    data
  })
}
//Slot别图表
export function getSlotChartData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/slot/data`,
    method: 'post',
    data
  })
}
//subunit别图表
export function getSubunitChartData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/subunit/data`,
    method: 'post',
    data
  })
}
//cst下钻详情
export function getCSTDetailData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/cst/detail`,
    method: 'post',
    data
  })
}
//subunit下钻详情
export function getSubunitDetailData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/subunit/cellTime`,
    method: 'post',
    data
  })
}
//设备别下钻详情
export function getDeviceDetailData(data = {}) {
  return request({
    url: `/agility/analytics/snapshot/device/cellTime`,
    method: 'post',
    data
  })
}
//归因分析后台更新状态获取
export function getAlarmAnalysisTaskStatus(serialCode) {
  return request({
    url: `/alarm/analysis/task/status/${serialCode}`,
    method: 'get'
  })
}
//更新告警图表
export function syncAllSnapshot(data) {
  return request({
    url: `/agility/analytics/snapshot/all/sync`,
    method: 'post',
    data
  })
}
//全局搜索
export function searchAlarmContent(params) {
  return request({
    url: `/alarm/searchAlarmContent`,
    method: 'get',
    params
  })
}

export function getVersions(params) {
  return request({
    url: `/alarm/getVersions`,
    method: 'get',
    params
  })
}

export function updateDefectTrendRet(data, params) {
  return request({
    url: `/alarm/updateDefectTrendRet`,
    method: 'put',
    data,
    params
  })
}
export function getAgilityAlgQO(serialCode) {
  return request({
    url: `/alarm/getAgilityAlgQO?serialCode=${serialCode}`,
    method: 'get'
  })
}